package com.ctshk.common.utils;

import com.ctshk.common.enums.SystemBusinessType;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;

/**
 * <p>
 *  根据业务类型system,会员等级,金额计算可获得积分
 * </p>
 *
 * @author 李新科
 * @date 2021/6/10 11:04
 */
public class CalcIntegralUtil {

    /**
     *
     * @param type 取枚举类SystemBusinessType
     * @param level 会员等级 1.银星会员,2.金星会员,3.铂星会员,4.五星会员
     * @param price 金额
     * @return
     */
    public static int getObtainByType(Integer type, Integer level, BigDecimal price) {
        int obtain = 0;
        if(SystemBusinessType.OUTBOUND_TRAVEL.getCode() == type || SystemBusinessType.INBOUND_TRAVEL.getCode() == type) {
            if(level > 0 && level < 3) {
                obtain = price.divide(new BigDecimal(3),0,BigDecimal.ROUND_DOWN).intValue();
            } else if(level > 2 && level < 5) {
                obtain = price.divide(new BigDecimal(2),0,BigDecimal.ROUND_DOWN).intValue();
            }
        } else if (SystemBusinessType.FIXED_PACKAGE_TICKET.getCode() == type || SystemBusinessType.DYNAMIC_PACKAGE_TICKET.getCode() == type) {
            if(level > 0 && level < 3) {
                obtain = price.divide(new BigDecimal(3),0,BigDecimal.ROUND_DOWN).intValue();
            } else if(level > 2 && level < 5) {
                obtain = price.divide(new BigDecimal(2),0,BigDecimal.ROUND_DOWN).intValue();
            }
        }  else if (SystemBusinessType.HOTEL.getCode() == type) {
            if(level > 0 && level < 3) {
                obtain = price.divide(new BigDecimal(10),0,BigDecimal.ROUND_DOWN).intValue();
            } else if(level > 2 && level < 5) {
                obtain = price.divide(new BigDecimal(5),0,BigDecimal.ROUND_DOWN).intValue();
            }
        } else if (SystemBusinessType.ATTRACTION_TICKET.getCode() == type) {
            if(level > 0 && level < 3) {
                obtain = price.divide(new BigDecimal(20),0,BigDecimal.ROUND_DOWN).intValue();
            } else if(level > 2 && level < 5) {
                obtain = price.divide(new BigDecimal(10),0,BigDecimal.ROUND_DOWN).intValue();
            }
        } else if (SystemBusinessType.AIR_TICKET.getCode() == type
                || SystemBusinessType.SHIP_TICKET.getCode() == type
                || SystemBusinessType.TRAIN_TICKET.getCode() == type
                || SystemBusinessType.AIR_EXPRESS.getCode() == type
                || SystemBusinessType.BUS_TICKET.getCode() == type) {
            if(level > 0 && level < 3) {
                obtain = price.divide(new BigDecimal(30),0,BigDecimal.ROUND_DOWN).intValue();
            } else if(level > 2 && level < 5) {
                obtain = price.divide(new BigDecimal(20),0,BigDecimal.ROUND_DOWN).intValue();
            }
        }

        return obtain;
    }

    public static BigDecimal getBigDecimalObtainByType(Integer type, Integer level, BigDecimal price) {
        return BigDecimal.valueOf(getObtainByType(type,level,price));
    }

    public static Long getLongObtainByType(Integer type, Integer level, BigDecimal price) {
        return Long.valueOf(getObtainByType(type,level,price));
    }
}
